package com.example.batch.entity.batch;

import com.example.batch.utils.Cast;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class ItemProcessorSubResult extends HashMap<String, Object> {

    public ItemProcessorSubResult() {}

    private <T> List<T> getList(String key) {
        return (List) Cast.cast(this.computeIfAbsent(key, (k) -> {
            return new ArrayList<>();
        }));
    }

    public <T> void addEntity(T entity) {
        if (entity != null) {
            this.putValue(entity.getClass().getSimpleName(), entity);
        }
    }

    private <T> void putValue(String key, T entity) {this.getList(key).add(entity);}

    private <T> void putValue(String key, List<T> entity) {this.getList(key).addAll(entity);}



}
